package com.whli.jee.system.controller;

import com.whli.jee.common.web.controller.BaseController;
import com.whli.jee.common.web.service.IBaseService;
import com.whli.jee.system.entity.SysBarcode;
import com.whli.jee.system.service.ISysBarcodeService;
import com.whli.jee.system.vo.SysBarcodeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * <em>条码生成</em>
 * @author whli
 * @version 2018/9/4 9:26
 * */
@RestController
@RequestMapping(value="/system/sysBarcode")
@Api(description = "条码生成API")
public class SysBarcodeController extends BaseController<SysBarcode, SysBarcodeVO>{

	@Autowired
	private ISysBarcodeService sysBarcodeService;
	
	@Override
    public IBaseService<SysBarcode> getService() {
        return sysBarcodeService;
    }

    /**
     * 验证编码唯一性
     * @param entity
     * @return
     */
    @PostMapping(value = "/validByNo")
    public boolean validByNo(SysBarcode entity){
	    SysBarcode temp = sysBarcodeService.validByNo(entity.getNo(),entity.getId());
	    if (temp != null){
	        return false;
        }
	    return true;
    }

    /**
     * 生成条码
     * @param entity
     */
    @PostMapping(value = "/generateBarcode")
    @ApiOperation("生成条码")
    public void generateBarcode(@RequestBody SysBarcode entity){
	    String barcode = sysBarcodeService.generateBarcode(entity.getNo());
        System.out.println("barcode == "+barcode);
    }
}

